package com.likl.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.likl.MyDataSource;

/**
 * ClassName:springboot
 * Description:
 *
 * @Create: 2024/6/27 15:41
 * @author: likl
 * @e-mail: likl1102@foxmail.com
 * @QQ: 2514927731
 */
@RestController
@RequestMapping("books")
public class BookController {
    //读取yaml文件中的自定义数据
    @Value("${name}")
    private String userName;

    @Value("${subject.shuxue}")
    private String subject;

    @Value("${likes[2]}")
    private String like;

    @Value("${dir}")
    private String dir;

    // 自动注入，将所有的数据封装到Environment对象中
    @Autowired
    private Environment environment;

    @Autowired
    private MyDataSource myDataSource;


    @GetMapping
    public String getBook() {
        System.out.println(userName + "‘s books");
        System.out.println(subject);
        System.out.println(like);
        System.out.println(dir);
        System.out.println("--------------");
        System.out.println(environment.getProperty("server.port"));
        System.out.println(myDataSource);
        return "book";
    }

    @GetMapping("/{id}")
    public String getBookOne(@PathVariable Integer id) {
        System.out.println("book" + id);
        return "book" + id;
    }
}
